<? 
// instantiate meeting manager
require('../includes/class.main.php');
$manager = new MeetingManager();
require('../includes/class.geocode.php');

// include admin header
include('../template/admin-header.php');


?>
<div class="left">
<?php 
include('menu.php');
?>
</div>

<div class="right">
	<h1>
		<span class="blue">Update Geocoding Data</span>
	</h1>
	<br>
	<form enctype="multipart/form-data" action="update-geocode.php"
		method="POST">
		<div class="adminForm">
			<br>
			<input style="margin-left:5em;margin-right:0em;margin-top:.8em" type="checkbox" name="rebuild" value="true"><span class="label">Rebuild Geocode Table</span>
			<br>
			<div class="submitBlock">
			
				<br>
				<input type="submit" name="submit" value="Update">
			</div>
			<br>
		</div>
	</form>
	<?
	if (isset($_POST['submit']))
	{
	?>
	<br>
	<br>
	<div>
	
	<?	
		if (isset($_POST['rebuild']) && $_POST['rebuild'] == "true") {
			$rebuild = true;
		} else { 
			$rebuild = false;
		}
			
		$geocoder = new GeocodeManager();
		$err = $geocoder->updateGeocodes($rebuild);
		
		echo "<span style=\"margin-left:8em\"><b>Geocoding Complete</b><br></span>";
	 	if ($err) {
	 		echo "<span style=\"margin-left:8em;color:red\"><b>Error $err</b><br></span>";
	 	} else {
	 		$geocodes = $geocoder->getGeocodes();
	 		$count = count($geocodes);
	 		echo "<span style=\"margin-left:8em\"><b>$count records processed</b><br></span>";
			echo "<br>";
	 		
			foreach ($geocodes as $geocode) {
				if ($geocode['status'] != "OK") {
					echo "<span style=\"color:red\">Error geocoding: ".$geocode['address1']
					." ".$geocode['city']." ".$geocode['zip']." ".$geocode['status']
					." ".$geocode['lat']." ".$geocode['lng']."</span><br>";
				}
			}
			
		}
	?>
	</div>
	<?
	}	
	
	
	?>
	
</div>

<?  include('../template/admin-footer.php'); ?>
